package 拷贝字节流;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class demo1 {
    public static void main(String[] args) {
//        任何类型的文件都可以拷贝
        FileInputStream fis = null;
        FileOutputStream myfile = null;
        try {
            fis = new FileInputStream("F:\\图片\\Saved Pictures\\截图\\拷贝测试.png");
            myfile = new FileOutputStream("F:\\桌面\\拷贝测试.png");
            byte[] bytes = new byte[1024*1024];     //一次最多拷贝1MB
            int readCount = 0;
            while ((readCount = fis.read(bytes)) != -1){
                myfile.write(bytes,0,readCount);
            }
            myfile.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (myfile != null){
                try {
                    myfile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
